package com.demo.service.impl;

import com.demo.domain.CtUser;
import com.demo.domain.User;
import com.demo.mapper.CtUserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Transactional
@org.springframework.stereotype.Service
public class Service {
    @Autowired
    private CtUserMapper ctUserMapper;

    public List<CtUser> selectAll(){
        return ctUserMapper.selectAll();
    }

    public Integer insertAll (CtUser ctUser) {
            return ctUserMapper.insertAll(ctUser);
    }

    public CtUser login(String mobile, String password) {
        System.out.println(mobile);
        System.out.println(password);
        // CtUser ctUser = new CtUser();
        // ctUser.setuEmail(uEmail);
        // ctUser.setuPassword(uPassword);
        // CtUser user = ctDao.login(uEmail, uPassword);
        CtUser login = ctUserMapper.login(mobile, password);
        System.out.println(login.getMobile());
        return login;

    }
    public List<CtUser> selectOne(String name){
        return ctUserMapper.selectOne(name);
    }
    public Integer delUser(@PathVariable("id")Integer id){
        return ctUserMapper.delUser(id);
    }
    public Boolean insertUser(String mobile, String password) {
        System.out.println(mobile + password);
/*        CtUser ctUser = ctUserMapper.login(mobile, password);
        System.out.println(ctUser);*/
        if (password != null) {
            ctUserMapper.insertUser(mobile, password);
            return true;
        } else {
            return false;
        }
    }
     public CtUser loginCode(String email) {
       return ctUserMapper.loginCode(email);
    }

    public Integer update(String mobile, String password) {
        return ctUserMapper.update(mobile, password);
    }

   public User allMsg(String shu) {
        return ctUserMapper.allMsg(shu);
    }

    public boolean yes(String shu) {
        if (ctUserMapper.yes(shu) != null) {
            return true;
        } else {
            return false;
        }
    }
}